t=input()
def pr(c):
    for i in range(2,c):
        if c%i==0:return 1
    return 0
if len(t.split())==3 and t.count('zero')+t.count('one')+t.count('two')+t.count('three')+t.count('four')+t.count('five')+t.count('six')+t.count('seven')+t.count('eight')+t.count('nine')==3:
    s=0
    d=0
    a = int(t.replace('zero','0').replace('one','1').replace('two','2').replace('three','3').replace('four','4').replace('five','5').replace('six','6').replace('seven','7').replace('eight','8').replace('nine','9').replace(' ',''))
    for i in range(a,1000):
        if pr(i)==1: s+=1
        else: break
    for i in range(a,99,-1):
        if pr(i)==1: d+=1
        else: break
    if d<s:print(a-d)
    else:print(a+s)
else: print("Wrong input")